

package com.hazelcast.test.starter.answer;

import org.mockito.invocation.InvocationOnMock;

import java.lang.reflect.Method;

/**
 * Default {@link org.mockito.stubbing.Answer} to create a mock for a proxied
 * container of a Hazelcast data structure, e.g.
 * {@link com.hazelcast.multimap.impl.MultiMapValue} or
 * {@link com.hazelcast.collection.impl.queue.QueueContainer}.
 */
class DataStructureContainerAnswer extends AbstractAnswer {

    DataStructureContainerAnswer(Object delegate) {
        super(delegate);
    }

    @Override
    Object answer(InvocationOnMock invocation, String methodName, Object[] arguments) throws Exception {
        if (arguments.length == 1 && methodName.equals("readAsData")) {
            // RingbufferContainer
            Method delegateMethod = getDelegateMethod(methodName, Long.TYPE);
            return invoke(delegateMethod, arguments);
        } else
            if (arguments.length == 1 && methodName.equals("getCollection")) {
                // MultiMapValue
                Method delegateMethod = getDelegateMethod(methodName, Boolean.TYPE);
                return invoke(delegateMethod, arguments);
            } else
                if (arguments.length == 0) {
                    return invoke(invocation);
                }
        throw new UnsupportedOperationException("Method is not implemented in DataStructureContainerAnswer: " + methodName);
    }
}
